﻿/*
created:     2025/08/22
filename:    zyt_logger.nsh
author:      liuqian
purpose:     封装安装包的日志打印接口
*/
!ifndef _ZYT_LOGGER_NSH_
!define _ZYT_LOGGER_NSH_

!ifndef ZYT_VERBOSE
!define ZYT_VERBOSE 3
!endif

!define TLLog `!insertmacro TLLogFun`
!define TLDetailPrint `!insertmacro TLDetailPrintFun`

Var TLFileHandle

!macro TLLogFun LogString
	!verbose push
	!verbose ${ZYT_VERBOSE}
	Push $0
	Push $1
	Push $2
	Push $3
	Push $4
	Push $5
	Push $6	
	${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
	Push $7
	System::Call 'kernel32::GetCurrentProcessId()i.r7'
	LogText "[pid=$7][$2/$1/$0 $4:$5:$6]${LogString}$\r$\n"
	Pop $7
	Pop $6
	Pop $5
	Pop $4
	Pop $3
	Pop $2
	Pop $1
	Pop $0
	!verbose pop	
!macroend

!macro TLDetailPrintFun LogString
	!verbose push
	!verbose ${ZYT_VERBOSE}
	Push $0
	Push $1
	Push $2
	Push $3
	Push $4
	Push $5
	Push $6	
	${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
	Push $7
	System::Call 'kernel32::GetCurrentProcessId()i.r7'
	DetailPrint "[pid=$7][$2/$1/$0 $4:$5:$6]${LogString}"
	Pop $7
	Pop $6
	Pop $5
	Pop $4
	Pop $3
	Pop $2
	Pop $1
	Pop $0
	!verbose pop	
!macroend

!define TLFileLog `!insertmacro TLFileLogFun`
!macro  TLFileLogFun LogString
	!verbose push
	!verbose ${ZYT_VERBOSE}
	Push $0
	Push $1
	Push $2
	Push $3
	Push $4
	Push $5
	Push $6	
	${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
	Push $7
	System::Call 'kernel32::GetCurrentProcessId()i.r7'
	FileWrite $TLFileHandle "[pid=$7][$2/$1/$0 $4:$5:$6]${LogString} $\r$\n"
	Pop $7
	Pop $6
	Pop $5
	Pop $4
	Pop $3
	Pop $2
	Pop $1
	Pop $0
	!verbose pop		
!macroend

!endif

